package top.tangyh.lamp.care.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.tangyh.basic.base.service.impl.SuperServiceImpl;
import top.tangyh.lamp.care.entity.BCareRecordsConfigNew;
import top.tangyh.lamp.care.manager.BCareRecordsConfigNewManager;
import top.tangyh.lamp.care.mapper.BCareRecordsConfigNewMapper;
import top.tangyh.lamp.care.mapper.BIoRecordMapper;
import top.tangyh.lamp.care.mapper.BObsvRecordMapper;
import top.tangyh.lamp.care.service.*;

import java.math.BigDecimal;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.util.StringUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.tangyh.lamp.base.entity.system.BaseRole;
import top.tangyh.lamp.care.common.CareCommonUtil;
import top.tangyh.lamp.care.entity.*;
import top.tangyh.lamp.care.mapper.BCareRecordsConfigNewMapper;
import top.tangyh.lamp.care.mapper.BIoRecordMapper;
import top.tangyh.lamp.care.mapper.BObsvRecordMapper;
import top.tangyh.lamp.care.service.*;
import top.tangyh.basic.base.service.impl.SuperServiceImpl;
import top.tangyh.lamp.care.manager.BCareRecordsConfigNewManager;
import top.tangyh.lamp.care.vo.query.IoItemQueryParam;
import top.tangyh.lamp.care.vo.result.*;
import top.tangyh.lamp.care.vo.save.BCareRecordsConfigNewSaveVO;
import top.tangyh.lamp.care.vo.save.CareRecordsConfigSaveVO;
import top.tangyh.lamp.care.vo.update.BCareRecordsConfigNewUpdateVO;
import top.tangyh.lamp.care.vo.query.BCareRecordsConfigNewPageQuery;
import top.tangyh.lamp.care.vo.update.CareRecordsConfigUpdateVO;
import top.tangyh.lamp.common.constant.CommonConstant;
import top.tangyh.lamp.common.constant.ModelItemConstant;
import top.tangyh.lamp.common.utils.ConvertUtil;
import top.tangyh.lamp.common.utils.PDateUtils;
import top.tangyh.lamp.common.utils.YDateUtils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;


/**
 * @author: zqb
 * @date: 2024/8/6 14:42
 */
@Slf4j
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class BCareRecordsConfigNewOneServiceImpl extends SuperServiceImpl<BCareRecordsConfigNewManager, Long, BCareRecordsConfigNew> implements BCareRecordsConfigNewOneService {


    private final BCareRecordsConfigNewMapper bCareRecordsConfigNewMapper;


    private final BCareRecordService bCareRecordService;


    private final BIoRecordService bIoRecordService;

    private final BObsvRecordService bObsvRecordService;


    private final BCareContentService bCareContentService;


    private final BPgRecordService bPgRecordService;


    private final BIoRecordMapper bIoRecordMapper;

    private final BCarePgVteService bCarePgVteService;


    private final BObsvRecordMapper bObsvRecordMapper;

    
    @Override
    public List<Map.Entry<String, List<Map>>> listOfDataNewOne(String patientIdent, String hospitalNumber, Long recordTime){
        //查询入科时间和出院时间(如果出院时间为null则取当前时间 )
        //查找入科消息 得到入科时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");


        //查询数据源类型的标题
        LambdaQueryWrapper<BCareRecordsConfigNew> wrapperCareRecordsConfig = new LambdaQueryWrapper<>();
        wrapperCareRecordsConfig.eq(BCareRecordsConfigNew::getIsDeleted, 0);
        wrapperCareRecordsConfig.eq(BCareRecordsConfigNew::getTitleType, 1);

        List<BCareRecordsConfigNew> listCareRecordsConfig = this.list(wrapperCareRecordsConfig);

        List<BCareRecordsConfigNew> uniqueDictValues = listCareRecordsConfig.stream().collect(
                Collectors.collectingAndThen(Collectors.toCollection(
                        () -> new TreeSet<>(Comparator.comparing(o -> o.getDictValue()))), ArrayList::new)
        );
        //需要查询的模块集合
        List<String> collectDictValue = uniqueDictValues.stream().map(BCareRecordsConfigNew::getDictValue).collect(Collectors.toList());

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //算出最早的 有数据的时间
//        String rkTimeStr = DateUtil.formatDateTime(yxHl7EventPORk.getEventTime());
//        String cyTimeStr = DateUtil.formatDateTime(cyTime);

        //开始时间
        String startTimeStr = YDateUtils.format(new Date(recordTime),YDateUtils.DATE_TIME_MINUTE_PATTERN)+":00";
        //结束时间
        String endTimeStr = YDateUtils.format(new Date(recordTime),YDateUtils.DATE_TIME_MINUTE_PATTERN)+":59";

        String minDate = bCareRecordsConfigNewMapper.getMinRecordTimeByParamNew(hospitalNumber, startTimeStr, endTimeStr, collectDictValue);

//        List<Map> ckdata = bObsvRecordService.getCktime(hospitalNumber, startTimeStr, endTimeStr);
//        if(CollectionUtil.isNotEmpty(ckdata)){
//            Long creatTime = (Long) ckdata.get(0).get("create_time");
//            Long mindata1 = YDateUtils.strToDate(minDate,YDateUtils.DATE_TIME_PATTERN).getTime();
//            if(creatTime < mindata1){
//                minDate = YDateUtils.dateToStr(new Date(creatTime));
//            }
//        }




        Map<String, List<Map>> mapData = new ConcurrentHashMap<>(16);
        //寻找有值的 开始时间 (每个模块中至少有个选项有值)
        //先列出来有哪些模块
//        评估评分	yx-pgpf  这期需要
//        观察项	yx-gcx  这期需要
//        出入量	yx-crl  这期需要
//        管道管理	yx-gdgl
//        护理操作	yx-hlcz  这期需要
//        护理交班	yx-hljb
//        护理记录	yx-hljl  这期需要
//        执行用药	yx-zxyy
//        日期时间	date_value
//        操作人员	operater
        List<BObsvRecord> listObsvResult = new ArrayList<>();
        //遍历赋值展示数据
        for (int i = 0; i < collectDictValue.size(); i++) {
            String dictValue = collectDictValue.get(i);
            if (StringUtil.isNotEmpty(dictValue)) {
                //        /*护理记录 数据 */
//        SELECT care_content,record_time from yx_care_content where type=1 and hospital_number='1004409' and record_time between '2021-12-01 09:00:00' and '2022-01-25 14:32:50'
                //先从  护理记录  模块寻找
                if (dictValue.equals(ModelItemConstant.MODEL_HLJL)) {
                    LambdaQueryWrapper<BCareContent> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(BCareContent::getType, 1);
                    wrapper.eq(BCareContent::getHospitalNumber, hospitalNumber);
                    wrapper.apply("record_time between '" + minDate + "' and '" + endTimeStr + "'");
                    List<BCareContent> list = bCareContentService.list(wrapper);
                    for (int j = 0; j < list.size(); j++) {
                        BCareContent po = list.get(j);
                        List<Map> mapList = new LinkedList<>();
                        //是否存在相同key 的时间
                        String strRecordTime = list.get(j).getRecordTime().format(dateTimeFormatter);
                        if (mapData.containsKey(strRecordTime + "@" + po.getUpdatedBy())) {
                            //根据这个时间获取 对应key的集合数据
                            List<Map> dataValue = mapData.get(strRecordTime + "@" + po.getUpdatedBy());

                            Map map = new LinkedHashMap();
                            map.put("hljl-careContent", po.getCareContent());
                            map.put("operator", po.getUpdatedBy());
                            map.put("hljl-reocrdId", po.getId());
//                            int width=CareCommonUtil.getStrWidth(po.getCareContent());
//
//                            map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(width),new BigDecimal(jishu),2));
                            map.put("create-time", YDateUtils.getTimestampOfDateTime(po.getCreatedTime()));
                            dataValue.add(map);
                            mapData.put(strRecordTime + "@" + po.getUpdatedBy(), dataValue);
                        } else {

                            Map map = new LinkedHashMap();
                            map.put("hljl-careContent", po.getCareContent());
                            map.put("operator", po.getUpdatedBy());
                            map.put("hljl-reocrdId", po.getId());
//                            int width=CareCommonUtil.getStrWidth(po.getCareContent());
//                            map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(width),new BigDecimal(jishu),2));
                            map.put("create-time", YDateUtils.getTimestampOfDateTime(po.getCreatedTime()));
                            mapList.add(map);
                            mapData.put(strRecordTime + "@" + po.getUpdatedBy(), mapList);
                        }

                    }

                    //评估评分
                } else if (dictValue.equals(ModelItemConstant.MODEL_PGPF)) {
                    //        /*评估评分 数据 */
//        SELECT grade_time,pg_id,show_value from yx_pg_record where hospital_number='1004409' and grade_time between '2021-12-01 09:00:00' and '2022-01-25 14:32:50'
                    LambdaQueryWrapper<BCareRecordsConfigNew> wrapperConfig = new LambdaQueryWrapper<>();
                    wrapperConfig.eq(BCareRecordsConfigNew::getDictValue, "yx-pgpf");
                    wrapperConfig.eq(BCareRecordsConfigNew::getIsDeleted, 0);
                    List<BCareRecordsConfigNew> listConfig = bCareRecordsConfigNewMapper.selectList(wrapperConfig);
                    List<Long> pgIdList = listConfig.stream()
                            .map(BCareRecordsConfigNew::getPgId).distinct()
                            .collect(Collectors.toList());

                    //只查询配置的那些评估评分记录
                    LambdaQueryWrapper<BPgRecord> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(BPgRecord::getHospitalNumber, hospitalNumber);
                    wrapper.in(pgIdList != null && !pgIdList.isEmpty(), BPgRecord::getPgId, pgIdList);
                    wrapper.apply("grade_time between '" + minDate + "' and '" + endTimeStr + "'");
                    List<BPgRecord> list = bPgRecordService.list(wrapper);


                    //		SELECT * from yx_care_records_config where dict_value='yx-pgpf' and is_deleted=0

                    for (int j = 0; j < list.size(); j++) {
                        BPgRecord po = list.get(j);

                        List<Map> mapList = new LinkedList<>();

                        String timeStr = DateUtil.format(list.get(j).getGradeTime(), "yyyy-MM-dd HH:mm:ss");
                        //是否存在相同key 的时间
                        if (mapData.containsKey(timeStr + "@" + po.getUpdatedBy())) {
                            List<Map> data_value = mapData.get(timeStr + "@" + po.getUpdatedBy());

                            Map map = new LinkedHashMap();
                            map.put("pgpf-pgId", po.getPgId());
                            map.put("pgpf-type", po.getPgType());
                            map.put("pgpf-showValue", po.getShowValue());
                            map.put("pgpf-reocrdId", po.getId());

//                            int contentWidth=CareCommonUtil.getStrWidth(po.getShowValue());
//                            map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));

                            map.put("operator", po.getUpdatedBy());
                            data_value.add(map);

                            mapData.put(timeStr + "@" + po.getUpdatedBy(), data_value);
                        } else {

                            Map map = new LinkedHashMap();
//
                            map.put("pgpf-pgId", po.getPgId());
                            map.put("pgpf-type", po.getPgType());
                            map.put("pgpf-showValue", po.getShowValue());
                            map.put("pgpf-reocrdId", po.getId());

//                            int contentWidth=CareCommonUtil.getStrWidth(po.getShowValue());
//                            map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));

                            map.put("operator", po.getUpdatedBy());
                            mapList.add(map);
                            mapData.put(timeStr + "@" + po.getUpdatedBy(), mapList);
                        }
                    }
                    //        /*观察项. 数据 */
//        SELECT from_unixtime(rec_time/1000, '%Y-%m-%d %H:%i:%S') rec_time,obsv_code,prop_value from yx_obsv_record  where hospital_number='1004409' and
//        from_unixtime(rec_time/1000, '%Y-%m-%d %H:%i:%S')  between '2021-12-01 09:00:00' and '2022-01-25 14:32:50'        and is_deleted=0
                } else if (dictValue.equals(ModelItemConstant.MODEL_GCX)) {
                    LambdaQueryWrapper<BObsvRecord> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(BObsvRecord::getHospitalNumber, hospitalNumber);
                    wrapper.eq(BObsvRecord::getIsDeleted, 0);
                    wrapper.apply("from_unixtime(rec_time/1000, '%Y-%m-%d %H:%i:%S') between '" + minDate + "' and '" + PDateUtils.dateToStr(new Date()) + "'");
                    List<BObsvRecord> list = bObsvRecordService.list(wrapper);
                    List<Map> mapList = new LinkedList<>();

                    for (int j = 0; j < list.size(); j++) {
                        BObsvRecord po = list.get(i);
                        Map data = new HashMap();
                        data.put("obsvCode", po.getObsvCode());
                        data.put("propValue", po.getPropValue());
                        // mapData.put(sdf.format(new Date(list.get(i).getRecTime())), data);
                        mapList.add(data);
                        mapData.put(sdf.format(new Date(list.get(i).getRecTime())), mapList);
                    }

                    
//                    listObsvResult =  bObsvRecordService.listCare(patientIdent,hospitalNumber,YDateUtils.strToDate(minDate,YDateUtils.DATE_TIME_PATTERN),YDateUtils.strToDate(endTimeStr,YDateUtils.DATE_TIME_PATTERN));
//                    for (int j = 0; j < listObsvResult.size(); j++) {
//                        BObsvRecord po = listObsvResult.get(j);
//
//                        String timeStr = DateUtil.format(new Date(listObsvResult.get(j).getRecTime()), "yyyy-MM-dd HH:mm:ss");
//
//                        List<Map> mapList = new LinkedList<>();
//
//                        //是否存在相同key 的时间
//                        if (mapData.containsKey(timeStr + "@" + po.getUpdatedBy())) {
//                            List<Map> data_value = mapData.get(timeStr + "@" + po.getUpdatedBy());
//
//                            Map map = new LinkedHashMap();
//                            if (StringUtil.isNotEmpty(po.getCreateSource())) {
//
//                                map.put("gcx-obsvCode", po.getObsvCode());
//                                map.put("gcx-propValue", po.getPropValue());
//                                map.put("gcx-recordId", po.getId());
////                                int contentWidth=CareCommonUtil.getStrWidth(po.getPropValue());
////                                map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
//
//                                if (po.getCreateSource().equals("dev")) {
//                                    map.put("operator", po.getCaijiren());
//                                    map.put("create-time", po.getCreatedTime().getTime());
//                                } else if (po.getCreateSource().equals("hand")) {
//                                    map.put("operator", po.getUpdatedBy());
//                                    map.put("create-time", po.getCreatedTime().getTime());
//                                }
//
//                            } else {
//                                map.put("gcx-obsvCode", po.getObsvCode());
//                                map.put("gcx-propValue", po.getPropValue());
//                                map.put("gcx-recordId", po.getId());
////                                int contentWidth=CareCommonUtil.getStrWidth(po.getPropValue());
////                                map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
//
//                                map.put("operator", po.getUpdatedBy());
//                                map.put("create-time", po.getCreatedTime().getTime());
//                            }
//                            data_value.add(map);
//
//                            mapData.put(timeStr + "@" + po.getUpdatedBy(), data_value);
//                        } else {
//
//                            Map map = new LinkedHashMap();
//                            if (StringUtil.isNotEmpty(po.getCreateSource())) {
//                                if (po.getCreateSource().equals("dev")) {
//                                    map.put("gcx-obsvCode", po.getObsvCode());
//                                    map.put("gcx-propValue", po.getPropValue());
//                                    map.put("gcx-recordId", po.getId());
////                                    int contentWidth=CareCommonUtil.getStrWidth(po.getPropValue());
////                                    map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
//
//                                    map.put("operator", po.getCaijiren());
//                                    map.put("create-time", po.getCreatedTime().getTime());
//                                } else if (po.getCreateSource().equals("hand")) {
//                                    map.put("gcx-obsvCode", po.getObsvCode());
//                                    map.put("gcx-propValue", po.getPropValue());
//                                    map.put("gcx-recordId", po.getId());
////                                    int contentWidth=CareCommonUtil.getStrWidth(po.getPropValue());
////                                    map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
//                                    map.put("operator", po.getUpdatedBy());
//                                    map.put("create-time", po.getCreatedTime().getTime());
//                                }
//                            } else {
//                                map.put("gcx-obsvCode", po.getObsvCode());
//                                map.put("gcx-propValue", po.getPropValue());
//                                map.put("gcx-recordId", po.getId());
////                                int contentWidth=CareCommonUtil.getStrWidth(po.getPropValue());
////                                map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
//                                map.put("operator", po.getUpdatedBy());
//                                map.put("create-time", po.getCreatedTime().getTime());
//                            }
//                            mapList.add(map);
//
//                            mapData.put(timeStr + "@" + po.getUpdatedBy(), mapList);
//                        }
//                    }

                    //        /*出入量 数据*/
//        SELECT model_code,item_code,io_value,time  from yx_io_record where time between '2021-12-01 09:00:00' and '2022-01-25 14:32:50'
//        and hospital_number='1004409' ORDER BY time
                } else if (dictValue.equals(ModelItemConstant.MODEL_CRL)) {
                    LambdaQueryWrapper<BIoRecord> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(BIoRecord::getHospitalNumber, hospitalNumber);
                    wrapper.eq(BIoRecord::getIsShowCare, CommonConstant.YES_NUMBER);
                    wrapper.apply("real_time between '" + minDate + "' and '" + endTimeStr + "'");
                    List<BIoRecord> list = bIoRecordService.list(wrapper);
                    for (int j = 0; j < list.size(); j++) {
                        BIoRecord po = list.get(j);

                        String timeStr = list.get(j).getRealTime().format(dateTimeFormatter);
                        List<Map> mapList = new LinkedList<>();
                        if (mapData.containsKey(timeStr + "@" + po.getUpdatedBy())) {
                            List<Map> dataValue = mapData.get(timeStr + "@" + po.getUpdatedBy());

                            Map map = new LinkedHashMap();
                            map.put("crl-modelCode", po.getModelCode());
                            map.put("crl-itemCode", po.getItemCode());
                            map.put("crl-ioValue", po.getIoValue());
                            map.put("crl-recordId", po.getId());
//                            int contentWidth=CareCommonUtil.getStrWidth(po.getIoValue());
//                            map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));

                            map.put("operator", po.getUpdatedBy());
                            dataValue.add(map);

                            mapData.put(timeStr + "@" + po.getUpdatedBy(), dataValue);
                        } else {

                            Map map = new LinkedHashMap();

                            map.put("crl-modelCode", po.getModelCode());
                            map.put("crl-itemCode", po.getItemCode());
                            map.put("crl-ioValue", po.getIoValue());
                            map.put("crl-recordId", po.getId());
//                            int contentWidth=CareCommonUtil.getStrWidth(po.getIoValue());
//                            map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
                            map.put("operator", po.getUpdatedBy());
                            mapList.add(map);

                            mapData.put(timeStr + "@" + po.getUpdatedBy(), mapList);
                        }

                    }
                    //        /*护理操作 数据*/
//        SELECT from_unixtime(mapped_time/1000, '%Y-%m-%d %H:%i:%S') mapped_time,item_value,item_code from yx_care_record
//        where hospital_number='1004409' and   from_unixtime(mapped_time/1000, '%Y-%m-%d %H:%i:%S')  between '2021-12-01 09:00:00' and '2022-01-25 14:32:50'
                } else if (dictValue.equals(ModelItemConstant.MODEL_HLCZ)) {
                    LambdaQueryWrapper<BCareRecord> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(BCareRecord::getHospitalNumber, hospitalNumber);
                    wrapper.apply("from_unixtime(mapped_time/1000, '%Y-%m-%d %H:%i:%S') between '" + minDate + "' and '" + endTimeStr + "'");


                    List<BCareRecord> list = bCareRecordService.list(wrapper);
                    for (int j = 0; j < list.size(); j++) {
                        BCareRecord po = list.get(j);

                        String timeStr = DateUtil.format(new Date(list.get(j).getMappedTime()), "yyyy-MM-dd HH:mm:ss");
                        List<Map> mapList = new LinkedList<>();
                        if (mapData.containsKey(timeStr + "@" + po.getUpdatedBy())) {
                            List<Map> dataValue = mapData.get(timeStr + "@" + po.getUpdatedBy());
                            Map map = new LinkedHashMap();
                            map.put("hlcz-itemValue", po.getItemValue());

//                            int contentWidth=CareCommonUtil.getStrWidth(po.getItemValue());
//                            map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
                            map.put("hlcz-recordId", po.getId());
                            map.put("hlcz-itemCode", po.getItemCode());
                            map.put("operator", po.getUpdatedBy());
                            dataValue.add(map);

                            mapData.put(timeStr + "@" + po.getUpdatedBy(), dataValue);
                        } else {
                            Map map = new LinkedHashMap();
                            map.put("hlcz-itemValue", po.getItemValue());
                            map.put("hlcz-recordId", po.getId());
//                            int contentWidth=CareCommonUtil.getStrWidth(po.getItemValue());
//                            map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));

                            map.put("hlcz-itemCode", po.getItemCode());
                            map.put("operator", po.getUpdatedBy());
                            mapList.add(map);

                            mapData.put(timeStr + "@" + po.getUpdatedBy(), mapList);
                        }
                    }
                    //入量
                } else if (dictValue.equals(ModelItemConstant.MODEL_CRL_IN)) {


                    LambdaQueryWrapper<BIoRecord> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(BIoRecord::getHospitalNumber, hospitalNumber);
                    wrapper.eq(BIoRecord::getPatientIdent, patientIdent);
                    wrapper.eq(BIoRecord::getModelCode, "yx-in");
//                    wrapper.eq(BIoRecord::getIsYaoSum, 1);
                    wrapper.eq(BIoRecord::getIsShowCare, CommonConstant.YES_NUMBER);
//                    wrapper.eq(YxHl7YzYaoPlanPO::getIsFromio, 0);
                    wrapper.apply("real_time between '" + startTimeStr + "' and '" + endTimeStr + "'");
                    List<BIoRecord> listIoRecord = bIoRecordService.list(wrapper);


                    List<BIoRecord> listHis = listIoRecord.stream().filter(e -> e.getSource().equals("his")).collect(Collectors.toList());

                    List<BIoRecord> listNoHis = listIoRecord.stream().filter(e -> !e.getSource().equals("his")).collect(Collectors.toList());


                    Map<String, List<BIoRecord>> collectsYaoPlan = listHis.stream().collect(Collectors.groupingBy(e -> fetchGroupKeyIoRecord(e)));

                    for (Map.Entry<String, List<BIoRecord>> entry : collectsYaoPlan.entrySet()) {
                        List<BIoRecord> poList = entry.getValue();


                        List<Map> mapList = new LinkedList<>();
                        String key = entry.getKey();

                        if (mapData.containsKey(key)) {
                            List<Map> dataValue = mapData.get(key);

                            //拿到主药
                            Optional<BIoRecord> havePoListMaster = poList.stream().filter(e -> e.getIsMaster() == 1).findFirst();
                            BIoRecord yxIoRecordPOMaste = new BIoRecord();
                            if (havePoListMaster.isPresent()) {
                                yxIoRecordPOMaste = havePoListMaster.get();
                            }


//                            List<BIoRecord> poListSun = poList.stream().filter(e -> e.getIsMaster() == 0).collect(Collectors.toList());

                            List<BIoRecord> poListSun = bIoRecordMapper.selectIoRecordByGroupId(yxIoRecordPOMaste.getHospitalNumber(), yxIoRecordPOMaste.getPatientIdent(), yxIoRecordPOMaste.getGroupId(), yxIoRecordPOMaste.getPlanTime());

                            StringBuilder name = new StringBuilder();
                            // name.append(yxIoRecordPOMaste.getMedication() + " " + yxIoRecordPOMaste.getDyAmount() + " " + yxIoRecordPOMaste.getDyAmountUnit());
                            Map map = new LinkedHashMap();
//
                            BigDecimal dyAmout = new BigDecimal(0);
                            if (StringUtil.isNotEmpty(yxIoRecordPOMaste.getDyAmount())) {
                                dyAmout = new BigDecimal(yxIoRecordPOMaste.getDyAmount());
                            }


                            //如果剂量和剂量单位不为空 就取 药名,剂量，剂量单位 否则取 药名,规格

                            if (null != yxIoRecordPOMaste && null != yxIoRecordPOMaste.getId()) {
                                if (StringUtil.isNotEmpty(yxIoRecordPOMaste.getDyAmount())) {
                                    map.put("yx-crl-in-yao-name", yxIoRecordPOMaste.getMedication() + " " + dyAmout.stripTrailingZeros().toPlainString() + " " + yxIoRecordPOMaste.getDyAmountUnit());
                                } else {
                                    map.put("yx-crl-in-yao-name", yxIoRecordPOMaste.getMedication() + " " + yxIoRecordPOMaste.getSpec());
                                }

                                map.put("operator", yxIoRecordPOMaste.getUpdatedBy());
                                map.put("yx-crl-in-yao-master-id", yxIoRecordPOMaste.getId());
                                map.put("item-code", yxIoRecordPOMaste.getItemCode());
                                map.put("yx-crl-in-id", yxIoRecordPOMaste.getId());
                                map.put("yx-crl-in-source", yxIoRecordPOMaste.getSource());
                                dataValue.add(map);
                            }


                            for (int j = 0; j < poListSun.size(); j++) {
                                BIoRecord yxIoRecordPOSun = poListSun.get(j);
                                Map mapsun = new LinkedHashMap();
                                if (StringUtil.isNotEmpty(yxIoRecordPOSun.getDyAmount())) {
                                    mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication() + " " + new BigDecimal(yxIoRecordPOSun.getDyAmount()).stripTrailingZeros().toPlainString() + " " + yxIoRecordPOSun.getDyAmountUnit());
                                } else {
                                    mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication() + " " + yxIoRecordPOSun.getSpec());
                                }
                                mapsun.put("item-code", yxIoRecordPOSun.getItemCode());
                                mapsun.put("operator", yxIoRecordPOSun.getUpdatedBy());
                                mapsun.put("yx-crl-in-id", yxIoRecordPOSun.getId());
                                mapsun.put("yx-crl-in-source", yxIoRecordPOSun.getSource());
                                dataValue.add(mapsun);

                            }


                            mapData.put(key, dataValue);
                        } else {


                            //拿到主药
                            Optional<BIoRecord> havePoListMaster = poList.stream().filter(e -> e.getIsMaster() == 1).findFirst();
                            BIoRecord yxIoRecordPOMaste = new BIoRecord();
                            if (havePoListMaster.isPresent()) {
                                yxIoRecordPOMaste = havePoListMaster.get();
                            }


//                            List<BIoRecord> poListSun = poList.stream().filter(e -> e.getIsMaster() == 0).collect(Collectors.toList());
                            List<BIoRecord> poListSun = bIoRecordMapper.selectIoRecordByGroupId(yxIoRecordPOMaste.getHospitalNumber(), yxIoRecordPOMaste.getPatientIdent(), yxIoRecordPOMaste.getGroupId(), yxIoRecordPOMaste.getPlanTime());

                            StringBuilder name = new StringBuilder();
                            // name.append(yxIoRecordPOMaste.getMedication() + " " + yxIoRecordPOMaste.getDyAmount() + " " + yxIoRecordPOMaste.getDyAmountUnit());
                            Map map = new LinkedHashMap();

                            //如果剂量和剂量单位不为空 就取 药名,剂量，剂量单位 否则取 药名,规格

                            BigDecimal dyAmout = new BigDecimal(0);
                            if (StringUtil.isNotEmpty(yxIoRecordPOMaste.getDyAmount())) {
                                dyAmout = new BigDecimal(yxIoRecordPOMaste.getDyAmount());
                            }
                            if (null != yxIoRecordPOMaste && null != yxIoRecordPOMaste.getId()) {
                                if (StringUtil.isNotEmpty(yxIoRecordPOMaste.getDyAmount())) {
                                    map.put("yx-crl-in-yao-name", yxIoRecordPOMaste.getMedication() + " " + dyAmout.stripTrailingZeros().toPlainString() + " " + yxIoRecordPOMaste.getDyAmountUnit());
                                } else {
                                    map.put("yx-crl-in-yao-name", yxIoRecordPOMaste.getMedication() + " " + yxIoRecordPOMaste.getSpec());
                                }
//                                map.put("yx-crl-in-yao-name", yxIoRecordPOMaste.getMedication() + " " + dyAmout.stripTrailingZeros().toPlainString() + " " + yxIoRecordPOMaste.getDyAmountUnit());
                                map.put("operator", yxIoRecordPOMaste.getUpdatedBy());
                                map.put("yx-crl-in-yao-master-id", yxIoRecordPOMaste.getId());
                                map.put("item-code", yxIoRecordPOMaste.getItemCode());
                                map.put("yx-crl-in-id", yxIoRecordPOMaste.getId());
                                map.put("yx-crl-in-source", yxIoRecordPOMaste.getSource());
                                mapList.add(map);
                            }


                            for (int j = 0; j < poListSun.size(); j++) {
                                BIoRecord yxIoRecordPOSun = poListSun.get(j);
                                Map mapsun = new LinkedHashMap();
                                if (StringUtil.isNotEmpty(yxIoRecordPOSun.getDyAmount())) {
                                    mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication() + " " + new BigDecimal(yxIoRecordPOSun.getDyAmount()).stripTrailingZeros().toPlainString() + " " + yxIoRecordPOSun.getDyAmountUnit());
                                } else {
                                    mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication() + " " + yxIoRecordPOSun.getSpec());
                                }
//                                mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication()+new BigDecimal(yxIoRecordPOSun.getDyAmount()).stripTrailingZeros().toPlainString() + " " + yxIoRecordPOSun.getDyAmountUnit());
                                mapsun.put("operator", yxIoRecordPOSun.getUpdatedBy());
                                mapsun.put("item-code", yxIoRecordPOSun.getItemCode());
                                mapsun.put("yx-crl-in-id", yxIoRecordPOSun.getId());
                                mapsun.put("yx-crl-in-source", yxIoRecordPOSun.getSource());
                                mapList.add(mapsun);
                            }

                            mapData.put(key, mapList);
                        }
                    }


                    //非his 数据处理
                    Map<String, List<BIoRecord>> collectsYaoPlanNoHis = listNoHis.stream().collect(Collectors.groupingBy(e -> fetchGroupKeyIoRecord(e)));
                    for (Map.Entry<String, List<BIoRecord>> entry : collectsYaoPlanNoHis.entrySet()) {


                        List<Map> mapList = new LinkedList<>();
                        String key = entry.getKey();
                        List<BIoRecord> listDataOfIoRecord = entry.getValue();


                        if (mapData.containsKey(key)) {
                            List<Map> dataValue = mapData.get(key);

                            for (int j = 0; j < listDataOfIoRecord.size(); j++) {
                                BIoRecord yxIoRecordPOSun = listDataOfIoRecord.get(j);
                                Map mapsun = new LinkedHashMap();
                                if (StringUtil.isNotEmpty(yxIoRecordPOSun.getDyAmount())) {
                                    mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication() + " " + new BigDecimal(yxIoRecordPOSun.getDyAmount()).stripTrailingZeros().toPlainString() + " " + yxIoRecordPOSun.getDyAmountUnit());
                                } else {
                                    mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication() + " " + yxIoRecordPOSun.getSpec());
                                }
                                mapsun.put("item-code", yxIoRecordPOSun.getItemCode());
                                mapsun.put("operator", yxIoRecordPOSun.getUpdatedBy());
                                mapsun.put("yx-crl-in-id", yxIoRecordPOSun.getId());
                                mapsun.put("yx-crl-in-source", yxIoRecordPOSun.getSource());
                                dataValue.add(mapsun);

                            }
                            mapData.put(key, dataValue);
                        } else{


                            for (int j = 0; j < listDataOfIoRecord.size(); j++) {
                                BIoRecord yxIoRecordPOSun = listDataOfIoRecord.get(j);
                                Map mapsun = new LinkedHashMap();
                                if (StringUtil.isNotEmpty(yxIoRecordPOSun.getDyAmount())) {
                                    mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication() + " " + new BigDecimal(yxIoRecordPOSun.getDyAmount()).stripTrailingZeros().toPlainString() + " " + yxIoRecordPOSun.getDyAmountUnit());
                                } else {
                                    mapsun.put("yx-crl-in-yao-name", yxIoRecordPOSun.getMedication() + " " + yxIoRecordPOSun.getSpec());
                                }
                                mapsun.put("item-code", yxIoRecordPOSun.getItemCode());
                                mapsun.put("operator", yxIoRecordPOSun.getUpdatedBy());
                                mapsun.put("yx-crl-in-id", yxIoRecordPOSun.getId());
                                mapsun.put("yx-crl-in-source", yxIoRecordPOSun.getSource());
                                mapList.add(mapsun);

                            }

                            mapData.put(key, mapList);
                        }


                    }
//





                } else if (dictValue.equals(ModelItemConstant.MODEL_CRL_OUT)) {


                    List<IoCodeDetailVO> list = bIoRecordMapper.selectIOOfDetail(ModelItemConstant.MODEL_CRL_OUT, hospitalNumber, minDate, endTimeStr);

//                    Map<LocalDateTime, List<IoCodeDetailVO>> collectsIoTime = list.stream().collect(Collectors.groupingBy(IoCodeDetailVO::getTime));
                    //为了 不同操作者 各种占一行 按照时间和操作人分组
                    Map<String, List<IoCodeDetailVO>> collectsIoTime = list.stream().collect(Collectors.groupingBy(e -> fetchGroupKeyCrl(e)));

                    for (Map.Entry<String, List<IoCodeDetailVO>> entry : collectsIoTime.entrySet()) {
                        List<IoCodeDetailVO> poList = entry.getValue();

                        String key = entry.getKey();

                        if (mapData.containsKey(key)) {
                            List<Map> dataValue = mapData.get(key);

                            for (int j = 0; j < poList.size(); j++) {
                                IoCodeDetailVO vo = poList.get(j);

                                Map map = new LinkedHashMap();
                                map.put("yx-crl-out-name", vo.getItemName());
                                map.put("yx-crl-out-value", vo.getIoValue() + "ml");
                                map.put("yx-crl-out-id", vo.getId());

                                map.put("operator", vo.getUpdatedBy());
                                map.put("item-code", vo.getItemCode());
                                dataValue.add(map);
                            }
                            mapData.put(key, dataValue);
                        } else {
                            List<Map> mapList = new LinkedList<>();

                            for (int j = 0; j < poList.size(); j++) {
                                IoCodeDetailVO vo = poList.get(j);
                                Map map = new LinkedHashMap();
                                map.put("yx-crl-out-name", vo.getItemName());
                                map.put("yx-crl-out-value", vo.getIoValue() + "ml");
                                map.put("yx-crl-out-id", vo.getId());
                                map.put("operator", vo.getUpdatedBy());
                                map.put("item-code", vo.getItemCode());
                                mapList.add(map);
                            }
                            mapData.put(key, mapList);
                        }

                    }

                } else if (dictValue.equals(ModelItemConstant.MODEL_VTE_DD)) {
                    //类型 ：1 vte 、2 肌酐、3 APACHEll、4 病人跌倒/坠床高危评估表（成人）、5 压力性损伤记录  、6  braden评分
                    LambdaQueryWrapper<BCarePgVte> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(BCarePgVte::getHospitalNumber, hospitalNumber);
                    wrapper.eq(BCarePgVte::getType, 4);
                    wrapper.eq(BCarePgVte::getIsDeleted, 0);
                    wrapper.apply("pf_time between '" + minDate + "' and '" + endTimeStr + "'");


                    List<BCarePgVte> list = bCarePgVteService.list(wrapper);
                    Map<String, List<BCarePgVte>> collectsIoTime = list.stream().collect(Collectors.groupingBy(e -> fetchGroupKeyVte(e)));

                    for (Map.Entry<String, List<BCarePgVte>> entry : collectsIoTime.entrySet()) {
                        List<BCarePgVte> poList = entry.getValue();

                        String key = entry.getKey();

                        if (mapData.containsKey(key)) {
                            List<Map> dataValue = mapData.get(key);

                            for (int j = 0; j < poList.size(); j++) {
                                BCarePgVte vo = poList.get(j);

                                Map map = new LinkedHashMap();
                                map.put("vte-dd-result", vo.getResult());
                                map.put("vte-dd-id", vo.getId());
//                                int contentWidth=CareCommonUtil.getStrWidth(vo.getResult());
//                                map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
//                                map.put("str-width",  contentWidth);
                                map.put("pf-type", vo.getPfType());
                                map.put("operator", vo.getUpdatedBy());

                                dataValue.add(map);
                            }
                            mapData.put(key, dataValue);
                        } else {
                            List<Map> mapList = new LinkedList<>();

                            for (int j = 0; j < poList.size(); j++) {
                                BCarePgVte vo = poList.get(j);
                                Map map = new LinkedHashMap();
                                map.put("vte-dd-result", vo.getResult());
                                map.put("vte-dd-id", vo.getId());
//                                int contentWidth=CareCommonUtil.getStrWidth(vo.getResult());
//                                map.put("str-multiple",  CareCommonUtil.devideResult(new BigDecimal(contentWidth),new BigDecimal(jishu),2));
//                                map.put("str-width",  contentWidth);
                                map.put("pf-type", vo.getPfType());
                                map.put("operator", vo.getUpdatedBy());

                                mapList.add(map);
                            }
                            mapData.put(key, mapList);
                        }

                    }


                } else if (dictValue.equals(ModelItemConstant.MODEL_VTE_BRADE)) {
                    //类型 ：1 vte 、2 肌酐、3 APACHEll、4 病人跌倒/坠床高危评估表（成人）、5 压力性损伤记录  、6  braden评分
                    LambdaQueryWrapper<BCarePgVte> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(BCarePgVte::getHospitalNumber, hospitalNumber);
                    wrapper.eq(BCarePgVte::getType, 6);
                    wrapper.eq(BCarePgVte::getIsDeleted, 0);
                    wrapper.apply("pf_time between '" + minDate + "' and '" + endTimeStr + "'");


                    List<BCarePgVte> list = bCarePgVteService.list(wrapper);
                    Map<String, List<BCarePgVte>> collectsIoTime = list.stream().collect(Collectors.groupingBy(e -> fetchGroupKeyVte(e)));

                    for (Map.Entry<String, List<BCarePgVte>> entry : collectsIoTime.entrySet()) {
                        List<BCarePgVte> poList = entry.getValue();

                        String key = entry.getKey();

                        if (mapData.containsKey(key)) {
                            List<Map> dataValue = mapData.get(key);

                            for (int j = 0; j < poList.size(); j++) {
                                BCarePgVte vo = poList.get(j);

                                Map map = new LinkedHashMap();
                                map.put("vte-brade-result", vo.getResult());
                                map.put("vte-brade-id", vo.getId());

                                map.put("operator", vo.getUpdatedBy());

                                dataValue.add(map);
                            }
                            mapData.put(key, dataValue);
                        } else {
                            List<Map> mapList = new LinkedList<>();

                            for (int j = 0; j < poList.size(); j++) {
                                BCarePgVte vo = poList.get(j);
                                Map map = new LinkedHashMap();
                                map.put("vte-brade-result", vo.getResult());
                                map.put("vte-brade-id", vo.getId());

                                map.put("operator", vo.getUpdatedBy());

                                mapList.add(map);
                            }
                            mapData.put(key, mapList);
                        }

                    }


                }
            }
        }


        //每一行必须要有某个模块某个选项有一个值的逻辑，去掉整条数据都是null的数据
        mapData.forEach((k, v) -> {
            // System.out.println(k + " : " + v);
            List<Map> rowData = v;
            AtomicBoolean haveDelete = new AtomicBoolean(false);
            for (int i = 0; i < rowData.size(); i++) {
                Map mapDataNode = rowData.get(i);
                mapDataNode.forEach((rowK, rowV) -> {
                    if (rowK.equals("hljl-careContent")) {
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("pgpf-showValue")) {
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("gcx-propValue")) {
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("crl-ioValue")) {
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("hlcz-itemValue")) {
                        //说明至少有一个选项有值
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("yx-crl-in-value")) {
                        //说明至少有一个选项有值
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("yx-crl-in-yao-name")) {
                        //说明至少有一个选项有值
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("yx-crl-out-value")) {
                        //说明至少有一个选项有值
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("vte-dd-result")) {
                        //说明至少有一个选项有值
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    } else if (rowK.equals("vte-brade-result")) {
                        //说明至少有一个选项有值
                        String content = (String) rowV;
                        if (StringUtil.isNotEmpty(content)) {
                            //说明至少有一个选项有值
                            haveDelete.set(true);
                        }
                    }


                });
            }


            //如果是false 代表整个map行的选项数值都是null
            if (haveDelete.compareAndSet(false, true)) {
                mapData.remove(k);
            }
        });
        //按照key里额时间值 做升序排序
        // 转换为list

//        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//
//        List<Date> haveDataDate = new LinkedList<>();
//        List<String> haveDataDataString = new LinkedList<>();
//        mapData.forEach((k, v) -> {
//
//            String dateStr = k;
//            if (dateStr.contains("@")) {
//                int i = dateStr.indexOf("@");//首先获取字符的位置
//                String newdateStr = dateStr.substring(0, i);
//                Date date = DateUtil.parse(newdateStr);
//                haveDataDate.add(date);
//                haveDataDataString.add(DateUtil.formatDate(date));
//            } else {
//                Date date = DateUtil.parse(dateStr);
//                haveDataDate.add(date);
//                haveDataDataString.add(DateUtil.formatDate(date));
//            }
//        });
//        Date dateRk = DateUtil.parseDateTime(startTimeStr);
//        //结束时间 date类型
//        Date cyTime = new Date(endTime);

//        //根据开始时间和结束时间返回时间段内的时间集合
//        List<String> listAllDates = YDateUtils.getDatesBetweenTwoDate(dateRk, cyTime);
//
//        //日期字符去重
//        List<String> uniqueListHaveData = haveDataDataString.stream().distinct().collect(Collectors.toList());
//        //去掉有数据的那些日期
//        List<String> dateAfterRemove = CareCommonUtil.listRemove(listAllDates, uniqueListHaveData);
//
//        //删除已经统计过的第一天日期
//        dateAfterRemove.removeIf(s -> s.contains(DateUtil.formatDate(dateRk)));
//        //排除已有统计中第一天的日期
//        uniqueListHaveData.removeIf(s -> s.contains(DateUtil.formatDate(dateRk)));
//
//        //先过滤出院那天的时间  单独统计
//        Date finalCyTime = cyTime;
//        dateAfterRemove.removeIf(s -> s.contains(DateUtil.formatDate(finalCyTime)));
//
//        //先过滤出院那天的时间  单独统计
//        uniqueListHaveData.removeIf(s -> s.contains(DateUtil.formatDate(finalCyTime)));
//
//
//        Collections.sort(uniqueListHaveData);




        List<Map.Entry<String, List<Map>>> list = new ArrayList<>(mapData.entrySet());
        // 使用list.sort()排序，按key排序
        // 排序
        list.sort(Comparator.comparing(Map.Entry::getKey));


        //获取限制行数
        AtomicReference<Integer> recordNum = new AtomicReference<>(null);
        listCareRecordsConfig.forEach(e -> {
            BCareRecordsConfigNew po = e;

            //日期时间	date_value
            if (po.getDictValue().equals("date_value")) {
                Integer num = po.getRecordNum();

                recordNum.set(num);
            }
        });

        if (null != recordNum.get()) {
            //判断要截取值是否大于当前集合数  如果大于则使用当前集合长度
            if (list.size() < recordNum.get()) {
                recordNum.set(list.size());
            }
            //list集合截取
            List<Map.Entry<String, List<Map>>> listResult = list.subList(0, recordNum.get());
            //2022-02-08 00:00


            return listResult;
        } else {
            return list;
        }
    }

    private static String fetchGroupKeyIoRecord(BIoRecord yxIoRecordPO) {
        return DateUtil.format(yxIoRecordPO.getRealTime(), "yyyy-MM-dd HH:mm:ss") + "@" + yxIoRecordPO.getUpdatedBy();
    }

    private static String fetchGroupKeyCrl(IoCodeDetailVO ioCodeDetailVO) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return ioCodeDetailVO.getRealTime().format(dateTimeFormatter) + "@" + ioCodeDetailVO.getUpdatedBy();
    }

    private static String fetchGroupKeyVte(BCarePgVte yxCarePgVtePO) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return yxCarePgVtePO.getPfTime().format(dateTimeFormatter) + "@" + yxCarePgVtePO.getUpdatedBy();
    }

    private static String fetchGroupKeyObsv(BObsvRecord obsvRecord) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return DateUtil.format(new Date(obsvRecord.getRecTime()), "yyyy-MM-dd HH:mm:ss") + "@" + obsvRecord.getPatientIdent();
    }
}
